@extends('layouts.admin')
@section('content')
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{url('admin/info')}}">首页</a> &raquo; <a href="{{url('admin/cate')}}">分类管理</a> &raquo; 编辑分类
    </div>
    <!--面包屑导航 结束-->
    
    <div class="result_wrap">
        <div class="result_title">
            <h3>提示信息:</h3>
            @if(count($errors))
                <div class="mark">
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <p style="font-size:14px;font-weight:bold">{{$error}}</p>
                        @endforeach
                    @else
                        <p style="font-size:14px;font-weight:bold">{{$errors}}</p>
                    @endif
                </div>
            @endif
        </div>
        <form action="{{url('admin/cate')}}/{{$field->cate_id}}" method="post">
            {{csrf_field()}}
            {{method_field('PUT')}}
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th width="120">父级分类：</th>
                        <td>
                            <select name="cate_pid" onchange="categoryCheck(this,{{$field->cate_id}})">
                                <option value="0">==顶级分类==</option>
                                @foreach($category as $cate)
                                    @if($cate->cate_id != $field->cate_id)
                                    <option value="{{$cate->cate_id}}"  @if($field->cate_pid == $cate->cate_id) selected="selected" @endif>{{$cate->cate_name}}</option>
                                    @endif
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>分类名称：</th>
                        <td>
                            <input type="text" name="cate_name"  value="{{$field->cate_name}}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>分类名称必须填写</span>
                        </td>
                    </tr>
                    <tr>
                        <th>标题：</th>
                        <td>
                            <input type="text" class="lg" name="cate_title" value="{{$field->cate_title}}">
                            <p>标题是对分类的的补充说明</p>
                        </td>
                    </tr>

                    <tr>
                        <th>排序：</th>
                        <td>
                            <input type="text" class="sm"  name="cate_order" value="{{$field->cate_order}}">
                        </td>
                    </tr>
                    <tr>
                        <th>关键词：</th>
                        <td>
                            <textarea name="cate_keywords">{{$field->cate_keywords}}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>描述：</th>
                        <td>
                            <textarea name="cate_description"></textarea>
                        </td>
                    </tr>


                    <tr>
                        <th></th>
                        <td>
                            <input type="submit" value="提交">
                            <input type="button" class="back" onclick="history.go(-1)" value="返回">
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
<script>
    function categoryCheck(obj,cate_id){
        if(obj.value != 0){
            $.post(
                    "{{url('admin/cate/categoryCheck')}}",
                    {"_token":"{{csrf_token()}}","cate_id":cate_id},
                    function (data){
                        if(data.status ==1){
                            layer.alert(data.msg, {
                                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                            })
                        }
                    }
            );
        }

    }
</script>
@endsection